<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0, user-scalable=0" name="viewport" />        
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" /> 
<meta content="telephone=no" name="format-detection" /> 
<title>投顾直播</title>
<link rel="stylesheet" href="css/playList.css">
</head>
<body>
<div class="container" id="div_template1">
	<!-- <div class="play-box">
		<div class="play-top">
			<div class="title">公开课－新三板收购理论知识与实践</div> -->
			<!-- 按钮状态
			playing		播放中
			preview		预告
			backview	回顾
			endview		结束 -->
			<!-- <div class="time">
				已播2小时36分钟 
				<span class="status-btn playing">直播中</span>
			</div>
		</div>
		<div class="video-box contributing">
			<div class="video-bg">
				<img src="./images/top-right-pic.png" alt="">
			</div>
			<div class="play-icon">
				<img src="./images/play-icon@2x.png" alt="">
			</div>

		</div>
		<div class="play-bottom">
			<div class="p-man">
				<div class="pic"><img src="./images/usr_pic.png" alt=""></div>
				<div class="name">肖俊贤</div>
			</div>

		</div>

	</div> -->
</div>
<script src="js/build/lib.js"></script>
<script src="js/lib/jquery.tmpl.min.js"></script>
<script src="js/lib/dropload.js"></script>

<script id="template1" type="text/x-jquery-tmpl">
{{each(i,video) data}}
	<div class="play-box">
		<div class="play-top">
			<div class="title">${video.subject}</div>
			<!-- 按钮状态
			playing		播放中
			preview		预告
			backview	回顾
			endview		结束 -->
			<div class="time">
				<!-- 已播2小时36分钟  -->
				${video.liveTime}
				{{if liveState ==1}}
		            <span class="status-btn playing">直播中</span>
		        {{else liveState ==0}}
		            <span class="status-btn preview">预告</span>
	            {{else liveState ==2}}
		            <span class="status-btn backview">回顾</span>
		        {{else}}
		            <span class="status-btn endview">结束</span>
		        {{/if}}
			</div>
		</div>
		<a class="video-box {{if needLogin}}contributing{{/if}}" href="javascript:;" url="${video.liveUrl}">
			<div class="video-bg">
				<img src="${video.imageUrl}" alt="">
			</div>
			<div class="play-icon">
				<img src="./images/play-icon@2x.png" alt="">
			</div>
		</a>
		<div class="play-bottom">
			{{each(i,man) video.adviserInfo}}
			<div class="p-man">
				<div class="pic"><img src="${man.avatar}" alt=""></div>
				<div class="name">${man.adviserName}</div>
			</div>
			{{/each}}
		</div>
	</div>
{{/each}}
</script>
<script>

var playList = {
	init: function(){
		var _url = 'http://live-dev-cstest.fzzqxf.com/live/list/info?pageIndex=1&pageSize=5';

		$.get('js/test.json',function(data){
			var _result = data;
			console.log(data);
			$('#template1').tmpl(_result).prependTo('#div_template1');
		});

		$('.dropload-down').delay(1200).show(1);
	},
	// 分页获取数据
	getMore: function(){
		// 页数
		var page = 0;
		// 每页展示5个
		var size = 5;

		// dropload
		$('.container').dropload({
		    scrollArea : window,
		    // autoLoad: true,
		    loadDownFn : function(me){
		        page++;
		        $.ajax({
		            type: 'GET',
		            // url: 'http://ons.me/tools/dropload/json.php?page='+page+'&size='+size,
		            url: 'json/d.json',
		            async:false,
		            dataType: 'json',
		            success: function(data){
		                var arrLen = data.data.length;

		                if(arrLen > 0){
		                	$('#template1').tmpl(data).prependTo('.container');
		                }else{
		                	// 如果没有数据,锁定
		                    me.lock();
		                    // 无数据
		                    me.noData();
		                    console.log('haha');
		                    me.opts.autoLoad =false;
		                    $('.dropload-down').hide();
		                }
	                    // 每次数据插入，必须重置
	                    me.resetload();
		            },
		            error: function(xhr, type){
		                alert('Ajax error!');
		                // 即使加载出错，也得重置
		                me.resetload();
		            }
		        });
		    }
		});
	},
	events: function(){
		$("body").delegate(".video-box","click",function(e){
			e.preventDefault();
			console.time("test");
			var _link = $(this).attr('url');
			var _needLogin = $(this).hasClass('contributing');
			var index = _link.lastIndexOf("\/");  
			var _str  = _link.substring(index + 1, _link.length);
			console.timeEnd("test");
			
			// console.log(_link);
			// console.log(_needLogin);
			// console.log(index, _str);
			if(_needLogin){
				window.location.href = 'http://www.baidu.com';
			}
		});
	},
	run: function(){
		this.init();
		this.getMore();
		this.events();
	}
};
playList.run();

</script>
</body>
</html>